﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Data.Entity;
using LanusMarket.Models;

namespace LanusMarket
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("Home", "", new { controller = "Home", action = "Index" });
            routes.MapRoute("AcercaDe", "About", new { controller = "Home", action = "About" });

            routes.MapRoute("LugaresDefault", "Lugares", new { controller = "Servicios", action = "Index" });
            routes.MapRoute("Lugares", "Lugares/{key}", new { controller = "Servicios", action = "Lugares", key = UrlParameter.Optional });            

            routes.MapRoute("Sitios", "Sitio/{key}", new { controller = "Sitios", action = "WebSite", key = UrlParameter.Optional });

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            // You can add custom code to this file. Changes will not be overwritten.
            // 
            // If you want Entity Framework to drop and regenerate your database
            // automatically whenever you change your model schema, add the following
            // code to the Application_Start method in your Global.asax file.
            // Note: this will destroy and re-create your database with every model change.
            // 
            // System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<LanusMarket.Models.LanusMarketContext>());

#if DEBUG
            System.Data.Entity.Database.SetInitializer<LanusMarketContext>(new LanusMarketInitializer());
#endif
        }
    }
}